// 生成首页路由
export function generateIndexRouter (data) {
  let indexRouter = [
    {
      path: '/notice',
      name: '公告管理',
      component: resolve => require(['@/views/children/notice/index.vue'], resolve),
      redirect: '/notice/list',
      children: [...generateChildRouters(data)]
    }
    // {
    //   path: '*',
    //   redirect: '/404',
    //   hidden: true
    // },
    // {
    //   path: '/404',
    //   hidden: true,
    //   component: resolve => require(['@/views/exception/404'], resolve)
    // }
  ]
  return indexRouter
}

// 生成嵌套路由（子路由）
function generateChildRouters (data) {
  const routers = []
  for (var item of data) {
    let component = 'views/' + item.component
    let menu = {
      path: item.path,
      name: item.name,
      component: resolve => require(['@/' + component + '.vue'], resolve),
      meta: {
        title: item.meta.title,
        icon: item.meta.icon
      }
    }
    if (item.children && item.children.length > 0) {
      menu.children = [...generateChildRouters(item.children)]
    }
    routers.push(menu)
  }
  return routers
}
